import Mock from 'mockjs'

// 获取分类列表  支持名称模糊查询（商品列表页面筛选项：输入分类名称，下拉选择框模糊查询出现数据）
export const getCategoryListPage = async (params: Category): Promise<ListCategoryRes> => {
  const res = await Mock.mock({
    'list|10': [
      {
        'id|+1': 1,
        'parentId|+1': 1,
        categoryName: '@cname',
        description: '@cparagraph',
        picUrl: '@image(800x400, @color, @color, @word)',
        'sortNo|+1': 1,
        'status|1': [0, 1],
        createTime: 1691727146870
      }
    ],
    total: 100,
    pageNo: 1,
    pageSize: 10
  })
  return res
}

// 获取分类
export const getCategory = async (id: Number): Promise<Category> => {
  const res = await Mock.mock({
    'id|+1': 1,
    'parentId|+1': 1,
    categoryName: '@cname',
    description: '@cparagraph',
    picUrl: '@image(800x400, @color, @color, @word)',
    'sortNo|+1': 1,
    'status|1': [0, 1],
    createTime: 1691727146870
  })
  return res
}

// 新增分类
export const createCategory = async (params: Category): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}

// 修改分类
export const updateCategory = async (params: Category): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}

// 删除分类
export const deleteCategory = async (id: number): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}

/**
 * 文件上传
 * FormData 存有多个文件
 */
export const uploadFile = async (params: FormData): Promise<{ url: string }> => {
  const res = await Mock.mock({
    url: '@image(200x200, @color, @word)'
  })
  return res
}

/**
 * 删除上传文件
 */
export const deleteUploadFile = async (url: stirng[]): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}
